package com.songkun.template.config;

import android.Manifest;
import android.app.Application;
import android.content.Context;
import android.support.v4.app.ActivityCompat;

import com.songkun.template.refrofit.rx.RxJavaExecutionHook;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;

import rx.plugins.RxJavaPlugins;


/**
 * @描述: APP全局
 * @项目名: AndroidTemplate
 * @包名: com.songkun.template.config
 * @类名:
 * @作者: soongkun
 * @创建时间: 2016/4/29 13:16
 */

public class AppApplication extends Application {

    private RefWatcher refWatcher;
    private static AppApplication instance;
    private static Context mContext;

    /**
     * 获取内存泄露的观察者
     *
     * @param context
     * @return
     */
    public static RefWatcher getRefWatcher(Context context) {
        AppApplication application = (AppApplication) context.getApplicationContext();
        return application.refWatcher;
    }


    @Override
    public void onCreate() {
        super.onCreate();
        this.instance = this;

        mContext = getContext();

        LeakCanary.install(this);
        RxJavaPlugins.getInstance().registerObservableExecutionHook(new RxJavaExecutionHook());
    }


    public static AppApplication getInstance() {
        return instance;
    }


    public static Context getContext() {
        return mContext;
    }
}
